package com.willpower.eureka.pojo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.List;

/**
 * @author: wen-yi;
 * @date: 2021/10/27 22:43;
 * @Description:
 */
@Data
@NoArgsConstructor
@TableName("sys_user")
public class User implements UserDetails {
    @TableId(value = "id",type = IdType.AUTO)
    private Integer id;
    //用户名
    private String username;
    //密码
    private String password;
    //昵称
    private String nickname;
    //性别
    private Integer sex;
    //邮箱
    private String email;
    //头像
    private String avatar;
    //手机号码
    private String phoneNumber;
    //生日
    private String birthday;
    //用户是否未过期
    private boolean accountNonExpired;
    //用户是否未被锁定
    private boolean accountNonLocked;
    //密码 凭证是否未过期
    private boolean credentialsNonExpired;
    //用户是否启用
    public boolean enabled;

    //返回用户生成的权限 权限不能返回null
    @TableField(exist = false)
    private List<GrantedAuthority> authorities;

    public User(String username, String password, List<GrantedAuthority> authorities) {
        this.username = username;
        this.password = password;
        this.authorities = authorities;
    }

    public User(String username, String password, boolean accountNonExpired, boolean accountNonLocked, boolean credentialsNonExpired, boolean enabled, List<GrantedAuthority> authorities) {
        this.username = username;
        this.password = password;
        this.accountNonExpired = accountNonExpired;
        this.accountNonLocked = accountNonLocked;
        this.credentialsNonExpired = credentialsNonExpired;
        this.enabled = enabled;
        this.authorities = authorities;
    }
}